<?php
class DireccionServiceUI
{
	private $paisObject;
	private $provinciaObject;
	private $partidoObject;
	private $cityObject;
	private $postalCodeObject;
	private $eighborhoodObject;
	private $Address1Object;
	private $Address2Object;
	private $Address3Object;
	private $heightObject;
	private $towerObject;
	private $floorObject;
	private $deptoObject;
	private $latitudeObject;
	private $longitudeObject;
	
	
	private function setObjectDireccion($model)
	{
		$paisObject 			= CHtml::activeId($model, 'direccion_pais_id');
		$provinciaObject 		= CHtml::activeId($model, 'direccion_provincia_id');
		$partidoObject 			= CHtml::activeId($model, 'address_departament_id');
		$cityObject 			= CHtml::activeId($model, 'direccion_localidad_id');
		$postalCodeObject 		= CHtml::activeId($model, 'address_postalcode_id');
		$eighborhoodObject 		= CHtml::activeId($model, 'address_neighborhood');
		$Address1Object 		= CHtml::activeId($model, 'address_address1');
		$Address2Object 		= CHtml::activeId($model, 'address_address2');
		$Address3Object 		= CHtml::activeId($model, 'address_address3');
		$heightObject 			= CHtml::activeId($model, 'address_height');
		$towerObject 			= CHtml::activeId($model, 'address_towername');
		$floorObject 			= CHtml::activeId($model, 'address_floorname');
		$deptoObject 			= CHtml::activeId($model, 'address_deptoname');
		$latitudeObject			= CHtml::activeId($model, 'address_latitude');
		$longitudeObject 		= CHtml::activeId($model, 'address_longitude');
	} 
	
	
	
	static public function getSelectCountry($form, $model,$modelAttributeName,$paisObject, $provinciaObject, $partidoObject, $cityObject )
	{
		return $form->dropDownList(
										$model,
                                        $modelAttributeName,
										CHtml::listData(
                                        					Pais::model()->getPaisesIdNombreActivo(),
                                                            'pais_id',
															'pais_nombre'
														),
										array(
												'onChange'=>CHtml::ajax(array(
															//'beforeSend' => 'js:beforeSendState(' . $provinciaObject .','.Yii::t('core_labels', 'loading') . ');',
															'beforeSend' => "js:direccion.beforeSendState('" . $paisObject . "','" 
																									. $provinciaObject . "','"
																									. $partidoObject . "','"
																									. $cityObject . "','"
																									. Yii::t('core_labels', 'Loading...') . 
																								"')",
															'type'=>'POST', //request type
															'url'=>Yii::app()->createUrl('direccion/provincia/HTMLProvincias'), //url to call.
															//Style: CController::createUrl('currentController/methodToCall')
															//'success'=>'js:' . $provinciaObject, //selector to update
															//'success'=>'js:function(data){alert(data)}',
															
															'success' => "js:function(data){ direccion.successSendState(data, '" 
																									. $paisObject . "','" 
																									. $provinciaObject . "','" 
																									. $partidoObject . "','" 
																									. $cityObject . "','"
																									. Yii::t('core_labels', 'Select') .
																								"');}",
															
															//'data'=>'js:javascript statement' 
															//leave out the data key to pass all form values through
														)
												
												),
												'prompt'=> t('Seleccionar','nucleo_etiqueta'),
											
										)
									);
	}

	static public function getSelectState($form, $model,$modelAttributeName,$paisObject, $provinciaObject, $partidoObject, $cityObject )
	{
		
		
		$dataStates = array(); 
		if(isset($model->pais->pais_id))//updated
		{
			$criteria = new CDbCriteria();
			$criteria->select = 'provincia_id, provincia_nombre';
			$criteria->condition = 'provincia_estado_id = 1';
			$criteria->condition .= ' and provincia_pais_id = :pais_id';
			$criteria->params = array(':pais_id'=>$model->pais->pais_id);
			
			$dataStates = CHtml::listData(
											Provincia::model()->findAll($criteria),
											'provincia_id',
											'provincia_nombre'
										);
		}
			
		return $form->dropDownList(
										$model,
                                        $modelAttributeName,
										$dataStates,
										array(
												'onChange'=>CHtml::ajax(array(
															//'beforeSend' => 'js:beforeSendState(' . $provinciaObject .','.Yii::t('core_labels', 'loading') . ');',
															'beforeSend' => "js:direccion.beforeSendCity('" . $paisObject . "','" 
																									. $provinciaObject . "','"
																									. $partidoObject . "','"
																									. $cityObject . "','"
																									. Yii::t('core_labels', 'Loading...') . 
																								"')",
															'type'=>'POST', //request type
															'url'=>Yii::app()->createUrl('direccion/Localidad/HTMLLocalidades'), //url to call.
															//Style: CController::createUrl('currentController/methodToCall')
															//'update'=>'#' . $cityObject, //selector to update
															'success' => "js:function(data){ direccion.successSendCity(data, '" 
																									. $paisObject . "','" 
																									. $provinciaObject . "','" 
																									. $partidoObject . "','" 
																									. $cityObject . "','"
																									. Yii::t('core_labels', 'Select') .
																								"');}",
															//'data'=>'js:javascript statement' 
															//leave out the data key to pass all form values through
														)
												
												),
												'prompt'=>t('Seleccionar','nucleo_etiqueta'),
											
										)
									);
	}

	static public function getSelectDepartament($form, $model,$modelAttributeName,$paisObject, $provinciaObject, $partidoObject, $cityObject )
	{
	}
	
	static public function getSelectCity($form, $model,$modelAttributeName,$paisObject, $provinciaObject, $partidoObject, $cityObject )
	{
		
		$dataCities = array();
		if(isset($model->provincia->provincia_id))//updated
		{
			$criteria = new CDbCriteria();
			$criteria->select = 'localidad_id, localidad_nombre';
			$criteria->condition = 'localidad_estado_id = 1 and localidad_pais_id = :pais_id and localidad_provincia_id = :provincia_id';
			$criteria->params = array(':pais_id'=>$model->pais->pais_id,':provincia_id'=>$model->provincia->provincia_id);
			
			
			$dataCities = CHtml::listData(
											Localidad::model()->findAll($criteria),
											'localidad_id',
											'localidad_nombre'
										);
		}
		return $form->dropDownList(
									$model,
									'direccion_localidad_id',
									$dataCities,
									array(
											'prompt'=>t('Seleccionar','nucleo_etiqueta'),
										)
									);
	}

}